﻿using System.Management;

namespace InfoPathHelpers.Internal
{
    internal static class WMIHelper
    {
        public static string GetProperty(string managementPath, string propertyName)
        {
            string PropertyValue = string.Empty;

            try
            {
                ManagementPath Path = new ManagementPath(managementPath);
                if (Path.IsInstance)
                {
                    ManagementObject Instance = new ManagementObject(Path);
                    PropertyValue = Instance[propertyName].ToString();
                }
                else if (Path.IsClass)
                {
                    ManagementClass Class = new ManagementClass(Path);
                    foreach (ManagementObject Instance in Class.GetInstances())
                    {
                        PropertyValue = Instance[propertyName].ToString();
                    }
                }
            }
            catch (ManagementException) { }

            return PropertyValue;
        }
    }
}
